package com.fire.security.controller;



import com.fire.security.core.page.TableDataInfo;
import com.fire.security.domain.Result;
import com.fire.security.domain.Shop;
import com.fire.security.service.ShopService;

import com.fire.security.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <h1>商铺管理控制类</h1>
 */
@RestController
@RequestMapping("/shop")
public class ShopController extends BaseController {

    // 注入ShopService
    @Autowired
    private ShopService shopService;



    /**
     * <h2>
     *     查询所有shop列表业务的url接口/shop/shop-list
     * </h2>
     * */
    @GetMapping("/shops")
    public List<Shop> shops(Shop shop) {
        return shopService.queryAllShop(shop);
    }

    @GetMapping("/shop-list")
    public TableDataInfo shopList(Shop shop) {
//        System.out.println("shop:" + shop.toString());
        startPage();
        List<Shop> list = shopService.queryAllShop(shop);
        return getDataTable(list);
    }

    /**
     * <h2>
     *    根据id查询shop信息的url接口/shop/shop-list-by-user-id
     * </h2>
     * */
    @GetMapping("/shop-list-by-user-id")
    public TableDataInfo shopListByUserId(@RequestParam("userId") String userId) {
        startPage();
        List<Shop> list = shopService.queryShopByUserId(userId);
        return getDataTable(list);
    }

    /**
    * <h2>
     *     添加shop业务的url接口/shop/shop-add
    * </h2>
    * */
    @PostMapping("/shop-add")
    public Result addShop(Shop shop) {
        // 执行业务
        Result result = shopService.insert(shop);
        // 响应
        return result;
    }

    /**
     * <h2>
     *     修改shop信息业务的url接口/shop/shop-update
     * </h2>
     * */
    @RequestMapping("/shop-update")
    public Result updateShop(@RequestBody Shop shop){

        // 执行业务
        Result result = shopService.updateById(shop);
        // 响应
        return result;
    }

    /**
     * <h2>
     *     删除shop业务的url接口/shop/shop-delete/{shopId}
     * </h2>
     * */
        @RequestMapping("/shop-delete")
    public Result deleteShop(String id) {

        // 执行业务
        Result result = shopService.deleteById(id);

        // 响应
        return result;
    }
}
